import 'package:base_plugin/base_plugin.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

mixin ScrollToHideMixin<T> on BaseProvider<T> {
  ScrollController controller = ScrollController();
  bool buttonBarIsUp = true;

  @override
  void initState() {
    super.initState();
    controller.addListener(_handleScrollUpdate);
  }

  @override
  void dispose() {
    super.dispose();
    controller.dispose();
  }

  void _handleScrollUpdate() {
    if (controller.position.userScrollDirection == ScrollDirection.reverse &&
        buttonBarIsUp == true) {
      //向下滑动
      buttonBarIsUp = false;
      update();
    }
    if (controller.position.userScrollDirection == ScrollDirection.forward &&
        buttonBarIsUp == false) {
      buttonBarIsUp = true;
      update();
    }
  }
}
